package cn.ai.boot.config.PCF;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DaSdkQuery {
    private int start = 0;
    private int limit;
    private int page;
    private List<String> froms;
    private List<String> selects;
    private List<DaSdkCondition> andList;
    private List<DaSdkCondition> orList;
    private List<DaQuerySdkOrder> orders;

    public static DaSdkQuery select(String... selects) {
        DaSdkQuery query = new DaSdkQuery();

        for(String select : selects) {
            query.addSelect(select);
        }

        return query;
    }

    public DaSdkQuery addSelect(String... selects) {
        if (this.selects == null) {
            this.selects = new ArrayList();
        }

        this.selects.addAll(Arrays.asList(selects));
        return this;
    }

    public DaSdkQuery removeAllSelect() {
        if (this.selects != null) {
            this.selects.clear();
        }

        return this;
    }

    public DaSdkQuery where(DaSdkCondition condition) {
        if (condition == null) {
            return this;
        } else {
            if (this.andList == null) {
                this.andList = new ArrayList();
            }

            this.andList.add(condition);
            return this;
        }
    }

    public DaSdkQuery and(DaSdkCondition... conditions) {
        if (conditions == null) {
            return this;
        } else {
            for(DaSdkCondition condition : conditions) {
                this.where(condition);
            }

            return this;
        }
    }

    public DaSdkQuery or(DaSdkCondition... conditions) {
        if (conditions == null) {
            return this;
        } else {
            if (this.orList == null) {
                this.orList = new ArrayList();
            }

            this.orList.addAll(Arrays.asList(conditions));
            return this;
        }
    }

    public DaSdkQuery order(DaQuerySdkOrder... orders) {
        for(DaQuerySdkOrder order : orders) {
            this.addOrder(order);
        }

        return this;
    }

    public DaSdkQuery start(int start) {
        this.start = start;
        return this;
    }

    public DaSdkQuery limit(int size) {
        this.limit = size;
        return this;
    }

    public void setStart(int start) {
        if (start >= 0) {
            this.start = start;
        }
    }

    public void setLimit(int limit) {
        if (limit >= 0 && limit <= 10000) {
            this.limit = limit;
        }
    }

    public void setPage(int page) {
        if (page >= 0 && page <= 10000) {
            this.page = page;
        }
    }

    public void addOrder(DaQuerySdkOrder order) {
        if (this.orders == null) {
            this.orders = new ArrayList();
        }

        this.orders.add(order);
    }

    public int getStart() {
        return this.start;
    }

    public int getLimit() {
        return this.limit;
    }

    public int getPage() {
        return this.page;
    }

    public List<String> getFroms() {
        return this.froms;
    }

    public void setFroms(List<String> froms) {
        this.froms = froms;
    }

    public List<String> getSelects() {
        return this.selects;
    }

    public void setSelects(List<String> selects) {
        this.selects = selects;
    }

    public List<DaSdkCondition> getAndList() {
        return this.andList;
    }

    public void setAndList(List<DaSdkCondition> andList) {
        this.andList = andList;
    }

    public List<DaSdkCondition> getOrList() {
        return this.orList;
    }

    public void setOrList(List<DaSdkCondition> orList) {
        this.orList = orList;
    }

    public List<DaQuerySdkOrder> getOrders() {
        return this.orders;
    }

    public void setOrders(List<DaQuerySdkOrder> orders) {
        this.orders = orders;
    }
}
